﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<%@ Import Namespace="CNTVNow.Web.Helpers.ExtensionMethods" %>

<ul class="sub">
    <% if (Session["account"] == null)
       { %>
            <li><a href="#"  id="signin">Log In</a></li>
            <%--<li><a href="#">Forgot Password</a></li>--%>
            <li class="last"><a href="/SignUp.cntv">Sign Up</a></li>
    <%}
       else
       {
           CNTVNow.Web.Models.AccountUser account = (CNTVNow.Web.Models.AccountUser)Session["account"];
           %>
            <li><a href="#"  id="hello">Welcome <%=account.AccountLastName + " " + account.AccountFirstName%></a></li>
            <li class="last"><a href="/Logout.cntv">Logout</a></li>
      <%} %>
</ul>

<fieldset id="signin_menu">
    <div style="height:20px;padding-right:5px; display:none; color:#B80104;" id="sign_errorMessage" class="signup_warring">
     </div>
    <form method="post" id="formsignin">
        <p>
            <label for="username">Username or email</label>
            <input id="sign_username" name="username" value="" title="username" tabindex="4" type="text">
        </p>
        <p>
            <label for="password">Password</label>
            <input id="sign_password" name="password" value="" title="password" tabindex="5" type="password">
        </p>
        <p class="rememberx">
            <input id="signin_submit" value="Sign in" style="height:30px;" tabindex="6" type="button" onclick="return CheckLogin();">
            <input id="remember" name="remember_me" value="1" tabindex="7" type="checkbox">
            <label for="remember">Remember me</label>
        </p>
        <p class="forgot"> 
            <a href="#" id="resend_password_link">Forgot your password?</a> 
        </p>
    </form>
</fieldset>
<script type="text/javascript">
    function CheckLogin() {
        if ($("#sign_username").val() == "") {
            $("#sign_errorMessage").html("Please input email");
            $("#sign_errorMessage").show();
            return false;
        }
        var positionAt = $("#sign_username").val().lastIndexOf('@');
        if (positionAt <= 0) {
            $("#sign_errorMessage").html("Please input email");
            $("#sign_errorMessage").show();
            return false;
        }

        var positionDot = $("#sign_username").val().lastIndexOf('.');
        if (positionDot <= 0) {
            $("#sign_errorMessage").html("Email not valid!");
            $("#sign_errorMessage").show();
            return false;
        }
        if (positionAt >= positionDot) {
            $("#sign_errorMessage").html("Email not valid!");
            $("#sign_errorMessage").show();
            return false;
        }

        if ($("#sign_password").val() == "") {
            $("#sign_errorMessage").html("Please input password");
            $("#sign_errorMessage").show();
            return false;
        }
        $("#sign_errorMessage").hide();
        $.ajax({
            url: "Login.cntv",
            data: { email: $("#sign_username").val(), password: $("#sign_password").val(), t: Date() },
            dataType: 'text',
            type: 'POST',
            success: function (responseText) {
                var data = eval("(" + responseText + ")");
                if (data.msg != "") {
                    $("#sign_errorMessage").html(data.msg);
                    $("#sign_errorMessage").show();
                    return false;
                }
                else {

                    $("#sign_errorMessage").hide();
                    document.location.href = ("Home.cntv");
                    return false;
                }
            }
        });
        
    }
</script>
<style>
        .signup_warring
        {
            background: url("<%=Url.GetUrlContentCommon("images/warning.png")%>") no-repeat scroll 10px center #FFD1D1;
            border: 1px solid #F8ACAC;
            color: #555555;
            margin-bottom: 15px;
            padding: 10px 10px 10px 33px;
        }
</style>
